package concurrency.chatper12;

import java.util.concurrent.TimeUnit;

/**
 * @author honway.liu
 * @date 2019/8/9 10:57 PM
 * @email gm100861@gmail.com
 * @blog http://linuxsogood.org
 */
public class ProducerThread extends Thread {

    private final MessageQueue messageQueue;

    public ProducerThread(MessageQueue messageQueue) {
        this.messageQueue = messageQueue;
    }

    @Override
    public void run() {
        while (true) {
            String name = Thread.currentThread().getName();
            messageQueue.put(new Message(name));
            System.out.println("put message: [" + name + "]");
            try {
                TimeUnit.MILLISECONDS.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
